<template>
	<div class="leftMenu" :class="$store.state.leftMenu.leftMenuMin && 'min'">
		<div class="zll-Menu">
			<!-- 特殊菜单 -->
			<el-menu v-if="user.flag"  :class="$store.state.leftMenu.colorData.index" :collapse="$store.state.leftMenu.leftMenuMin"
				:collapse-transition="false" :default-active="specialMenuIndex[$route.name]" class="el-menu-vertical-demo">
				<SpecialMenuList  :menuData="specialLeftMenuData"></SpecialMenuList>
			</el-menu>

			<!-- 正常菜单 -->
			<el-menu v-else :class="$store.state.leftMenu.colorData.index" :collapse="$store.state.leftMenu.leftMenuMin"
				:collapse-transition="false" :default-active="menuIndexs[$route.name]" class="el-menu-vertical-demo">
				<MenuList :menuData="LeftMenuData"></MenuList>
			</el-menu>
		</div>
	</div>
</template>

<script>
	import LeftMenuData from './leftMenuData';
	import specialLeftMenuData from './specialLeftMenuData';
	import MenuList from './menuList';
	import SpecialMenuList from './specialMenuList';
	import { getStore } from "@/plugins/localStore";

	export default {
		components: { MenuList,SpecialMenuList },
		data() {

			// 正常菜单
			function menuIndexsGet(menuData, parentIndex, menuIndexData) {
				menuData = menuData ? menuData : LeftMenuData;
				menuIndexData = menuIndexData ? menuIndexData : {};
				parentIndex = parentIndex ? parentIndex : '';
				for (let i = 0; i < menuData.length; i++) {
					if (menuData[i].name) {
						menuIndexData[menuData[i].name] = parentIndex ? (parentIndex + '-' + i) : i.toString();
					}
					if (menuData[i].children && menuData[i].children.length) {
						menuIndexsGet(menuData[i].children, parentIndex ? (parentIndex + '-' + i) : i.toString(), menuIndexData)
					}
				}
				return menuIndexData;
			}
			let menuIndexData = menuIndexsGet();


			// 特殊菜单
			function specialMenuIndexsGet(menuData, parentIndex, menuIndexData) {
				menuData = menuData ? menuData : specialLeftMenuData;
				menuIndexData = menuIndexData ? menuIndexData : {};
				parentIndex = parentIndex ? parentIndex : '';
				for (let i = 0; i < menuData.length; i++) {
					if (menuData[i].name) {
						menuIndexData[menuData[i].name] = parentIndex ? (parentIndex + '-' + i) : i.toString();
					}
					if (menuData[i].children && menuData[i].children.length) {
						menuIndexsGet(menuData[i].children, parentIndex ? (parentIndex + '-' + i) : i.toString(), menuIndexData)
					}
				}
				return menuIndexData;
			}
			let specialMenuIndexData = specialMenuIndexsGet();


			return {
				LeftMenuData: LeftMenuData,
				specialLeftMenuData:specialLeftMenuData,
				activeNum: "1",
				menuIndexs: menuIndexData,
				specialMenuIndex:specialMenuIndexData,
				isCollapse: false, //菜单折叠
				nowTime: new Date(),
				nowDate: new Date(),
				sysInfo: { copyRight: '' },
				user:getStore()
			};
		},
		methods: {
			getSysInfo() {
				let self = this;
				self.$http({
					url: "/jinl/sysInfo/getSysInfoList",
					method: "post",
				}).then(resp => {
					if (resp.success) {
						self.sysInfo = resp.result;
					}
				});
			},
			getdateFormat() {
				//显示时间
				var _this = this;
				let yy = String(new Date().getFullYear());
				let mm = new Date().getMonth() + 1;
				let dd = String(new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate());
				let hou = String(new Date().getHours() < 10 ? "0" + new Date().getHours() : new Date().getHours());
				let min = String(new Date().getMinutes() < 10 ? "0" + new Date().getMinutes() : new Date().getMinutes());
				let sec = String(new Date().getSeconds() < 10 ? "0" + new Date().getSeconds() : new Date().getSeconds());
				_this.nowTime = hou + ":" + min + ":" + sec;
				_this.nowDate = yy + "-" + mm + "-" + dd;
			},
		},
		mounted() {
			this.getdateFormat(); //时间
			setInterval(() => {
				this.getdateFormat();
			}, 1000);
		}
	};
</script>

<style scoped lang="scss">
	@import "@/style/LeftMenu.scss";

	.leftMenu {
		.bottom_bq {
			width: 150px;
			margin-top: 30px;
			height: 30px;
			line-height: 30px;
			overflow: hidden;
			padding: 0 5px;
			color: #fff;
			transform: scale(0.8);
			position: fixed;
			bottom: 10px;
			background: #284358;
		}

		&.min {
			.bottom_bq {
				width: 64px;
			}
		}
	}
</style>